<?php

namespace App\Filament\Resources\Posts\Schemas;

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;

class PostForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('user_id')
                    ->label('作者')
                    ->relationship('user', 'name')
                    ->required(),
                Select::make('category_id')
                    ->label('分类')
                    ->relationship('category', 'name'),
                TextInput::make('title')
                    ->label('标题')
                    ->required(),
                TextInput::make('slug')
                    ->label('别名')
                    ->required(),
                Textarea::make('excerpt')
                    ->label('摘要')
                    ->columnSpanFull(),
                Textarea::make('content')
                    ->label('内容')
                    ->required()
                    ->columnSpanFull(),
                FileUpload::make('featured_image')
                    ->label('特色图片')
                    ->image(),
                Select::make('status')
                    ->label('状态')
                    ->options([
                        'draft' => '草稿',
                        'published' => '已发布',
                        'scheduled' => '定时发布',
                        'archived' => '已归档',
                    ])
                    ->default('draft')
                    ->required(),
                Select::make('access_level')
                    ->label('访问权限')
                    ->options([
                        'public' => '公开',
                        'login_required' => '需要登录',
                        'followers_only' => '仅关注者',
                        'private' => '私密',
                    ])
                    ->default('public')
                    ->required(),
                TextInput::make('password')
                    ->label('密码保护')
                    ->password(),
                DateTimePicker::make('published_at')
                    ->label('发布时间'),
                TextInput::make('views_count')
                    ->label('浏览量')
                    ->required()
                    ->numeric()
                    ->default(0),
                TextInput::make('likes_count')
                    ->label('点赞数')
                    ->required()
                    ->numeric()
                    ->default(0),
                TextInput::make('comments_count')
                    ->label('评论数')
                    ->required()
                    ->numeric()
                    ->default(0),
                Toggle::make('is_featured')
                    ->label('推荐文章')
                    ->required(),
                Toggle::make('is_sticky')
                    ->label('置顶文章')
                    ->required(),
                Toggle::make('allow_comments')
                    ->label('允许评论')
                    ->default(true),
                Toggle::make('is_approved')
                    ->label('已审核')
                    ->default(false),
                TextInput::make('meta_title')
                    ->label('SEO标题'),
                Textarea::make('meta_description')
                    ->label('SEO描述')
                    ->columnSpanFull(),
                Textarea::make('meta_keywords')
                    ->label('SEO关键词')
                    ->columnSpanFull(),
            ]);
    }
}
